from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.common.by import By
from conftest import *

# input标签赋值
def inputText(inputTag: WebElement,text):
    inputTag.clear()
    inputTag.send_keys(text)


def login(wd, username, password):
    wd.get(ADMIN)
    wd.implicitly_wait(10)
    span = wd.find_element(By.TAG_NAME, "span")
    # 判断是否跳转到登陆页
    assert span.text == '大佬请登录'
    wd.implicitly_wait(10)
    # 开始登陆
    inputTags = wd.find_elements(By.TAG_NAME, "input")
    # for inputTag in inputTags:
    #     inputTag.send_keys("admin")
    inputText(inputTags[0], username)
    inputText(inputTags[1], password)
    submitButton = wd.find_element(By.XPATH, "//span[text() = 'Submit']/..")
    submitButton.click()
    wd.implicitly_wait(10)
    res = wd.find_element(By.TAG_NAME, "h5")
    assert res.text == "仅帅哥可见"
    wd.implicitly_wait(10)